<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_videochapter extends Controller_Abstract {
	
	/**
	 * 视频
	 */
	function actionIndex()
	{

		$this->union_table = videochapter::meta();

		//获取搜索参数
		$this->get_param();
		//初始化分页信息
		$this->_format_page_info();
		//$this->param = array_merge($this->param,array("video_id"=>$videoid));
		$dis_param = new helper_disposeparam($this->param);
		$sql = $dis_param->getsql();//OUT PUT用
		//dump($sql);die;
		$_SESSION['lastsql'] = $sql;//OUT PUT用
		$obj = call_user_func_array(array($this->union_table,'find'), $sql);
		$item = $obj->limitPage($this->curr_page,$this->page_size)
					->order('weight asc')
					->fetchPagination($this->pagination)
					->getall();
		$this->_view['item'] = $item;
		$this->_view['pagination'] = $this->pagination;	
		$this->_view['orderField'] = 'weight';
		$this->_view['orderDirection'] = 'asc';
		$this->_view['video_id'] =$this->_context->video_id;

	}
	 
	/**
	 * 视频设置
	 */
	 
	function actionAdd() {
	    //设置要操作的表单，并设置自动插入方式
	    $this->union_table = videochapter::meta ();
	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_videochapter_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );
	     
 
	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    $result = $handle->add ( $form, 'id', $_GET );
	    if ($this->_context->isGET ()) {
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';
	        $res = video::getliveselect($_SESSION['acct']['id']);
	        if(!$this->_context->id){
	        	$form->element('video_id')->value = $this->_context->video_id;
	        }
	        
	        $form->element('live_id')->items= $res;
	    } else {
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加章节视频,id :' . $handle->form_database_obj->id );
	        }else{
	            Syslog::logs ( '编辑章节视频,id :' . $handle->form_database_obj->id );
	        }
	         
	        if($handle->status=='success')
	        	//
	            $this->_context->forwardUrl = url("videochapter/index")."/index/video_id/".$this->_context->video_id;
	        return call_user_func_array(array($this,$handle->status),array($result));
	    }
	     
	}
	 
	/**
	 * 删除视频标签
	 */
	function actionDel() {
	     Syslog::logs("删除章节视频，ID：".print_r($this->_context->ids,true));
	     $this->union_table = videochapter::meta();
	     $this->delete(array('id'=>$this->_context->ids));    	  
	}

	/**
	 * 题目列表
	 * @Author   xy
	 * @DateTime 2020-03-17T17:38:36+0800
	 * @return   [type]                   [description]
	 */
	function actionquestion(){
		$this->_view['chapter_id'] = $this->_context->chapter_id;
		$this->union_table = videoquestion::meta();
		$this->lists();
	}

	function actionaddquestion(){
		$this->union_table = videoquestion::meta ();
	    $handle = new helper_autoinsert ( $this->union_table );
	    $form = new Form_videochapter_addquestion ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );
	     
 
	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    $result = $handle->add ( $form, 'id', $_GET );
	    if ($this->_context->isGET ()) {
	        //传递$form值
	        $this->_view ['form'] = $result;
	        $this->_viewname = '../form/add';
	        // $res = video::getliveselect($_SESSION['acct']['id']);
	        if(!$this->_context->id){
	        	$form->element('chapter_id')->value = $this->_context->chapter_id;
	        }
	    } else {
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加章节视频,id :' . $handle->form_database_obj->id );
	        }else{
	            Syslog::logs ( '编辑章节视频,id :' . $handle->form_database_obj->id );
	        }
	         
	        if($handle->status=='success')
	        	//
	            $this->_context->forwardUrl = url("videochapter/question")."/chapter_id/".$this->_context->chapter_id;
	        return call_user_func_array(array($this,$handle->status),array($result));
	    }
	}

	function actiondelquestion(){
		Syslog::logs("删除视频题目，ID：".print_r($this->_context->ids,true));
	     $this->union_table = videoquestion::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}

	function actiondolog(){
		$this->_view['chapter_id'] = $this->_context->chapter_id;
		$this->union_table = videoexam::meta();
		$this->lists();
	}

	function actiondodetail(){
		$this->_view['item'] = videoquestiondolog::find('exam_id=?',$this->_context->exam_id)->getAll();
	}


}


